﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Reflection;
using System.Globalization;

namespace ImPM.Application
{
    public static class ProductVersion
    {
        // Fields
        private static FileVersionInfo _fileVersionInfo = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
        private static Version _version = Assembly.GetExecutingAssembly().GetName().Version;

        // Methods
        public static string GetFullyQualifiedTypeName(string partialTypeName)
        {
            Exceptions.ThrowIfNull(partialTypeName, "partialTypeName");
            bool flag = true;
            string str = partialTypeName;
            int index = partialTypeName.IndexOf(',');
            if ((index >= 0) && (partialTypeName.IndexOf("PublicKeyToken=", index, StringComparison.OrdinalIgnoreCase) >= 0))
            {
                flag = false;
            }
            if (flag)
            {
                Type type = typeof(ProductVersion);
                string assemblyQualifiedName = type.AssemblyQualifiedName;
                int startIndex = assemblyQualifiedName.IndexOf(',', 0);
                startIndex = assemblyQualifiedName.IndexOf(',', startIndex + 1);
                str = string.Format(CultureInfo.InvariantCulture, "{0}{1}", new object[] { partialTypeName, assemblyQualifiedName.Substring(startIndex, assemblyQualifiedName.Length - startIndex) });
            }
            return str;
        }

        public static string GetFullyQualifiedTypeName(string assemblyName, string typeFormat, params object[] args)
        {
            Exceptions.ThrowIfNull(assemblyName, "assemblyName");
            Exceptions.ThrowIfNull(typeFormat, "typeFormat");
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(CultureInfo.InvariantCulture, typeFormat, args);
            builder.Append(", ");
            builder.Append(assemblyName);
            return GetFullyQualifiedTypeName(builder.ToString());
        }

        // Properties
        public static string FileVersion
        {
            get
            {
                return _fileVersionInfo.FileVersion;
            }
        }

        public static string FullVersion
        {
            get
            {
                return _version.ToString();
            }
        }
    }


}
